package com.ruoyi.flowable.listener.move.moveRepair;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.equ.domain.EquMove;
import com.ruoyi.equ.domain.EquRepair;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 移动-维修-6监听
 */
@Slf4j
@Component("moveRepairListener_6")
public class MoveRepairListener_6 implements ExecutionListener {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void notify(DelegateExecution execution) {
        try {
            //财务确认
            String flag6 = execution.getVariable("flag6", String.class);
            String differentPart = execution.getVariable("differentPart", String.class);

            //移动-执行信息
            EquMove equMove = execution.getVariable("equMove", EquMove.class);
            Map<String, Object> executeInfoMap = objectMapper.readValue(equMove.getExecuteInfo(), new TypeReference<Map<String, Object>>() {});
            HashMap<String, Object> dataMap = new HashMap<>();
            dataMap.put("维修费用与材料清单是否一致", flag6);
            dataMap.put("差异项", differentPart);
            executeInfoMap.put("维修-财务确认", dataMap);
            String executeInfo = objectMapper.writeValueAsString(executeInfoMap);

            equMove.setExecuteInfo(executeInfo);
            execution.setVariable("equMove", equMove);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
